import LoadingComponent from '../../components/common/loading.vue'

let $vm, loading = {};

loading.install = function(Vue, options) {
    if (!$vm) {
        const LoadingPlugin = Vue.extend(LoadingComponent); // 1、创建构造器，定义好提示信息的模板

        $vm = new LoadingPlugin({
            el: document.createElement('div')
        });

        document.body.appendChild($vm.$el);
    }

    $vm.show = false;

    let loading = {
        show(text) {
            $vm.show = true;
        },
        hide() {
            $vm.show = false;
        }
    };

    if (!Vue.$loading) {
        Vue.$loading = loading;
    }

    Vue.prototype.$loading = Vue.$loading;

    // Vue.mixin({
    //     created() {
    //         this.$loading = Vue.$loading;
    //     }
    // })
}

export default loading;